#ifndef PLANE_H_
#define PLANE_H_

#include "Point.h"
#include "Vector.h"
#include "Object.h"

namespace Geometry
{
	class Plane : public Object
	{
		Vector m_normal;
		Point  m_point;

	public:

		Plane():Object(){}
	    Plane( Vector _n, Point _p ):Object(),m_normal(_n),m_point(_p){}
	    Plane( Vector _n, Point _p, Properties::Color _c, Properties::Lighting _l ):Object(_c, _l),m_normal(_n),m_point(_p){}

		inline Vector n() const { return m_normal; };
		inline Point  p() const { return m_point; };

		virtual bool intersect(const Ray& _r, Point& _p, float& _t);
		inline virtual Ray getReflectedRay( const Ray& _incoming, const Point& _p );
		inline virtual Vector getNormal( const Point& _p ) { return m_normal.unit(); }
	};

	inline Ray Plane::getReflectedRay( const Ray& _incoming, const Point& _p )
	{
		Vector& V = _incoming.q().unit();
		Vector& N = getNormal( _p );
		Vector& R = ( 2 * ( V * N ) * N ) - V;

		return Ray( _p , R );
	}
}

#endif